<template>
  <div>
    <el-row type="flex" justify="space-between" align="middle" style="height: 40px">
      <el-col>
        <strong v-if="isRoot" class="title-head"><i class="el-icon-office-building" /> {{ treeNode.name }}</strong>
        <span v-else>{{ treeNode.name }}</span>
      </el-col>
      <el-col :span="4">
        <el-row type="flex" justify="end">
          <!-- 负责人 -->
          <el-col>{{ treeNode.manager }}</el-col>
          <el-col>
            <!-- 下拉菜单 element -->
            <el-dropdown>
              <span class="xia">
                操作<i class="el-icon-arrow-down" />
              </span>
              <!-- 下拉菜单 -->
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="addpart">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" @click.native="editDepts">编辑部门</el-dropdown-item>
                <el-dropdown-item v-if="!isRoot" @click.native="delpartment">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { delpartment } from '@/api/departments'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    async delpartment() {
      // 二次询问
      await this.$confirm('是否确定删除')
      // 发请求
      await delpartment(this.treeNode.id)
      // 提示用户操作成功
      this.$message.success('操作成功')
      this.$emit('del')
    },
    addpart() {
      this.$emit('addpart', this.treeNode)
    },
    editDepts() {
      this.$emit('editDepts', this.treeNode)
    }
  }
}
</script>

<style>

</style>
